package com.gitee.luosl.cola.match.guard;

import com.gitee.luosl.cola.lang.Tuple2;
import com.gitee.luosl.cola.lang.Tuple3;
import com.gitee.luosl.cola.lang.Tuple4;
import com.gitee.luosl.cola.lang.function.Predicate3;
import com.gitee.luosl.cola.lang.function.Predicate4;

import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * Created by luosl on 2021/04/06/9:30
 */
public interface Guard<T> {

    boolean test(T value);

    static <T> Guard<T> of(Predicate<T> predicate) {
        return predicate::test;
    }

    static <T> Guard<T> of(Supplier<Boolean> supplier){
        return value -> supplier.get();
    }

    static <T1, T2> Guard<Tuple2<T1, T2>> of(BiPredicate<T1, T2> predicate){
        return value -> value.test(predicate);
    }

    static <T1, T2, T3> Guard<Tuple3<T1, T2, T3>> of(Predicate3<T1, T2, T3> predicate){
        return value -> value.test(predicate);
    }

    static <T1, T2, T3, T4> Guard<Tuple4<T1, T2, T3, T4>> of(Predicate4<T1, T2, T3, T4> predicate){
        return value -> value.test(predicate);
    }
}
